math / data /lean /OAI /Computability /DepthThree /HashBool.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.13 kB
import OAI.Computability.DepthThree.HashAffine
namespace OAI
namespace DepthThreeLowerBound.BinaryHash
open BinaryAlgebra
variable {d r : β„•}
theorem hashBool_eq_iff (u : Fin (d + r - 1) β†’ Bool)
(x : Fin d β†’ Bool) (a : Fin r β†’ Bool) :
hashBool u x = a ↔
hashF2 (bitsEquivF2 (Fin (d + r - 1)) u) (bitsEquivF2 (Fin d) x) =
bitsEquivF2 (Fin r) a := by
rw [← bitsEquivF2_hashBool]
exact (bitsEquivF2 (Fin r)).injective.eq_iff.symm
theorem hashBool_collision_iff (u : Fin (d + r - 1) β†’ Bool)
(x y : Fin d β†’ Bool) :
hashBool u x = hashBool u y ↔
hashF2 (bitsEquivF2 (Fin (d + r - 1)) u) (bitsEquivF2 (Fin d) x) =
hashF2 (bitsEquivF2 (Fin (d + r - 1)) u) (bitsEquivF2 (Fin d) y) := by
rw [← bitsEquivF2_hashBool, ← bitsEquivF2_hashBool]
exact (bitsEquivF2 (Fin r)).injective.eq_iff.symm
def hashBool_fiberEquiv (x : Fin d β†’ Bool) (a : Fin r β†’ Bool) :
{u : Fin (d + r - 1) β†’ Bool // hashBool u x = a} ≃
{u : Seed d r // hashF2 u (bitsEquivF2 (Fin d) x) =
bitsEquivF2 (Fin r) a} :=
Equiv.subtypeEquiv (bitsEquivF2 (Fin (d + r - 1)))
(fun u => hashBool_eq_iff u x a)
theorem hashBool_fiber_card (x : Fin d β†’ Bool) (hx : x β‰  fun _ => false)
(a : Fin r β†’ Bool) :
Fintype.card {u : Fin (d + r - 1) β†’ Bool // hashBool u x = a} = 2 ^ (d - 1) := by
classical
have hnonzero : bitsEquivF2 (Fin d) x β‰  0 := by
intro h
apply hx
funext i
apply bitValue_injective
simpa using congrFun h i
exact (Fintype.card_congr (hashBool_fiberEquiv x a)).trans
(hashF2_fiber_card (bitsEquivF2 (Fin d) x) hnonzero (bitsEquivF2 (Fin r) a))
def hashBool_collisionEquiv (x y : Fin d β†’ Bool) :
{u : Fin (d + r - 1) β†’ Bool // hashBool u x = hashBool u y} ≃
{u : Seed d r // hashF2 u (bitsEquivF2 (Fin d) x) =
hashF2 u (bitsEquivF2 (Fin d) y)} :=
Equiv.subtypeEquiv (bitsEquivF2 (Fin (d + r - 1)))
(fun u => hashBool_collision_iff u x y)
theorem hashBool_collision_card (x y : Fin d β†’ Bool) (hxy : x β‰  y) :
Fintype.card {u : Fin (d + r - 1) β†’ Bool // hashBool u x = hashBool u y} =
2 ^ (d - 1) := by
classical
exact (Fintype.card_congr (hashBool_collisionEquiv (r := r) x y)).trans
(hashF2_collision_card (bitsEquivF2 (Fin d) x) (bitsEquivF2 (Fin d) y)
(fun h => hxy ((bitsEquivF2 (Fin d)).injective h)))
def boolCoordinateCube (T : Finset (Fin d)) (rho : {i : Fin d // i βˆ‰ T} β†’ Bool) :
Set (Fin d β†’ Bool) :=
{x | βˆ€ i (hi : i βˆ‰ T), x i = rho ⟨i, hi⟩}
theorem mem_boolCoordinateCube_iff (T : Finset (Fin d))
(rho : {i : Fin d // i βˆ‰ T} β†’ Bool) (x : Fin d β†’ Bool) :
x ∈ boolCoordinateCube T rho ↔
bitsEquivF2 (Fin d) x ∈ coordinateCube T (fun i => bitValue (rho i)) := by
constructor
Β· intro hx i hi
change bitValue (x i) = bitValue (rho ⟨i, hi⟩)
exact congrArg bitValue (hx i hi)
Β· intro hx i hi
exact bitValue_injective (hx i hi)
theorem injOn_hashBool_iff (u : Fin (d + r - 1) β†’ Bool)
(T : Finset (Fin d)) (rho : {i : Fin d // i βˆ‰ T} β†’ Bool) :
Set.InjOn (hashBool u) (boolCoordinateCube T rho) ↔
Set.InjOn (hashF2 (bitsEquivF2 (Fin (d + r - 1)) u))
(coordinateCube T (fun i => bitValue (rho i))) := by
constructor
Β· intro hinj x hx y hy hxy
obtain ⟨a, rfl⟩ := (bitsEquivF2 (Fin d)).surjective x
obtain ⟨b, rfl⟩ := (bitsEquivF2 (Fin d)).surjective y
have hab := hinj ((mem_boolCoordinateCube_iff T rho a).mpr hx)
((mem_boolCoordinateCube_iff T rho b).mpr hy)
((hashBool_collision_iff u a b).mpr hxy)
exact congrArg (bitsEquivF2 (Fin d)) hab
Β· intro hinj x hx y hy hxy
apply (bitsEquivF2 (Fin d)).injective
exact hinj ((mem_boolCoordinateCube_iff T rho x).mp hx)
((mem_boolCoordinateCube_iff T rho y).mp hy)
((hashBool_collision_iff u x y).mp hxy)
def hashBool_badSeedEquiv (T : Finset (Fin d))
(rho : {i : Fin d // i βˆ‰ T} β†’ Bool) :
{u : Fin (d + r - 1) β†’ Bool // Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)} ≃
{u : Seed d r // Β¬ Set.InjOn (hashF2 u)
(coordinateCube T (fun i => bitValue (rho i)))} :=
Equiv.subtypeEquiv (bitsEquivF2 (Fin (d + r - 1)))
(fun u => not_congr (injOn_hashBool_iff u T rho))
open scoped Classical in
theorem hashBool_badSeed_card_le (T : Finset (Fin d))
(rho : {i : Fin d // i βˆ‰ T} β†’ Bool) :
Fintype.card
{u : Fin (d + r - 1) β†’ Bool // Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)} ≀
(2 ^ T.card - 1) * 2 ^ (d - 1) := by
classical
calc
Fintype.card
{u : Fin (d + r - 1) β†’ Bool // Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)} =
Fintype.card {u : Seed d r // Β¬ Set.InjOn (hashF2 u)
(coordinateCube T (fun i => bitValue (rho i)))} :=
Fintype.card_congr (hashBool_badSeedEquiv (r := r) T rho)
_ = (badSeeds (r := r) T (fun i => bitValue (rho i))).card := by
simp only [badSeeds, Fintype.card_subtype]
_ ≀ (2 ^ T.card - 1) * 2 ^ (d - 1) := badSeeds_card_le T _
end DepthThreeLowerBound.BinaryHash
end OAI