introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.03 kB
import OAI.Computability.DepthThree.AlgebraBits
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Data.Fintype.BigOperators
import Lean.Elab.Tactic.Omega
namespace OAI
namespace DepthThreeLowerBound.BinaryHash
open scoped BigOperators
abbrev F2 := BinaryAlgebra.F2
abbrev Data (d : β„•) := Fin d β†’ F2
abbrev Seed (d r : β„•) := Fin (d + r - 1) β†’ F2
abbrev Output (r : β„•) := Fin r β†’ F2
def sumIndex {d r : β„•} (i : Fin r) (s : Fin d) : Fin (d + r - 1) :=
⟨i.val + s.val, by have := i.isLt; have := s.isLt; omega⟩
@[simp] theorem sumIndex_val {d r : β„•} (i : Fin r) (s : Fin d) :
(sumIndex i s).val = i.val + s.val := rfl
theorem sumIndex_left_injective {d r : β„•} (s : Fin d) :
Function.Injective (fun i : Fin r => sumIndex i s) := by
intro i j h
apply Fin.ext
have hval := congrArg Fin.val h
simpa only [sumIndex_val, Nat.add_right_cancel_iff] using hval
def hashF2 {d r : β„•} (u : Seed d r) (x : Data d) : Output r :=
fun i => βˆ‘ s : Fin d, u (sumIndex i s) * x s
@[simp] theorem hashF2_apply {d r : β„•} (u : Seed d r) (x : Data d) (i : Fin r) :
hashF2 u x i = βˆ‘ s : Fin d, u (sumIndex i s) * x s := rfl
@[simp] theorem hashF2_zero_data {d r : β„•} (u : Seed d r) :
hashF2 u 0 = 0 := by
funext i
simp [hashF2]
@[simp] theorem hashF2_zero_seed {d r : β„•} (x : Data d) :
hashF2 (0 : Seed d r) x = 0 := by
funext i
simp [hashF2]
theorem hashF2_add_data {d r : β„•} (u : Seed d r) (x y : Data d) :
hashF2 u (x + y) = hashF2 u x + hashF2 u y := by
funext i
simp [hashF2, mul_add, Finset.sum_add_distrib]
theorem hashF2_sub_data {d r : β„•} (u : Seed d r) (x y : Data d) :
hashF2 u (x - y) = hashF2 u x - hashF2 u y := by
funext i
simp [hashF2, mul_sub, Finset.sum_sub_distrib]
theorem hashF2_add_seed {d r : β„•} (u v : Seed d r) (x : Data d) :
hashF2 (u + v) x = hashF2 u x + hashF2 v x := by
funext i
simp [hashF2, add_mul, Finset.sum_add_distrib]
theorem hashF2_sub_seed {d r : β„•} (u v : Seed d r) (x : Data d) :
hashF2 (u - v) x = hashF2 u x - hashF2 v x := by
funext i
simp [hashF2, sub_mul, Finset.sum_sub_distrib]
def hashBool {d r : β„•} (u : Fin (d + r - 1) β†’ Bool) (x : Fin d β†’ Bool) :
Fin r β†’ Bool :=
fun i => BinaryAlgebra.fieldBit
(hashF2 (fun j => BinaryAlgebra.bitValue (u j))
(fun s => BinaryAlgebra.bitValue (x s)) i)
@[simp] theorem bitValue_hashBool {d r : β„•}
(u : Fin (d + r - 1) β†’ Bool) (x : Fin d β†’ Bool) (i : Fin r) :
BinaryAlgebra.bitValue (hashBool u x i) =
hashF2 (fun j => BinaryAlgebra.bitValue (u j))
(fun s => BinaryAlgebra.bitValue (x s)) i := by
simp [hashBool]
theorem bitsEquivF2_hashBool {d r : β„•}
(u : Fin (d + r - 1) β†’ Bool) (x : Fin d β†’ Bool) :
BinaryAlgebra.bitsEquivF2 (Fin r) (hashBool u x) =
hashF2 (BinaryAlgebra.bitsEquivF2 (Fin (d + r - 1)) u)
(BinaryAlgebra.bitsEquivF2 (Fin d) x) := by
funext i
exact bitValue_hashBool u x i
end DepthThreeLowerBound.BinaryHash
end OAI