Download data/lean/OAI/Computability/DepthThree/HashProbability.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DepthThree/HashProbability.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/DepthThree/HashProbability.lean
-
curl -L -o HashProbability.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DepthThree/HashProbability.lean
8.1 kB
| import OAI.Computability.DepthThree.HashBool | |
| import OAI.Computability.DepthThree.FiniteProbabilityBounds | |
| import OAI.Computability.DepthThree.RestrictionProbability | |
| import Mathlib.Tactic.NormNum | |
| import Mathlib.Tactic.Positivity | |
| namespace OAI | |
| universe uDepth1 uDepth2 | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| namespace DepthThreeLowerBound | |
| theorem finiteProb_eq_card_div {Ξ© : Type uDepth1} [Fintype Ξ©] (P : Ξ© β Prop) : | |
| finiteProb P = (Fintype.card {Ο // P Ο} : β) / Fintype.card Ξ© := by | |
| simp [finiteProb, finiteAvg, Fintype.card_subtype, div_eq_mul_inv, mul_comm] | |
| private theorem finiteProb_eq_card_div_decidable {Ξ© : Type uDepth2} [Fintype Ξ©] | |
| (P : Ξ© β Prop) [DecidablePred P] : | |
| finiteProb P = (Fintype.card {Ο // P Ο} : β) / Fintype.card Ξ© := by | |
| rw [finiteProb_eq_card_div] | |
| exact congrArg (fun k : β => (k : β) / Fintype.card Ξ©) | |
| (congrArg (.card {Ο // P Ο}) (Subsingleton.elim _ _)) | |
| namespace BinaryHash | |
| variable {d r : β} | |
| private theorem normalize_hash_count (hd : 0 < d) (c : β) : | |
| c * (2 : β) ^ (d - 1) / (2 : β) ^ (d + r - 1) = c / (2 : β) ^ r := by | |
| have he : d + r - 1 = (d - 1) + r := by omega | |
| rw [he, pow_add, mul_comm c] | |
| exact mul_div_mul_left c _ (pow_ne_zero _ (by norm_num)) | |
| theorem hashBool_fiber_probability (x : Fin d β Bool) | |
| (hx : x β fun _ => false) (a : Fin r β Bool) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => hashBool u x = a) = | |
| ((2 : β) ^ r)β»ΒΉ := by | |
| have hd : 0 < d := by | |
| by_contra h | |
| have hd0 : d = 0 := by omega | |
| subst d | |
| exact hx (Subsingleton.elim _ _) | |
| rw [finiteProb_eq_card_div_decidable | |
| (fun u : Fin (d + r - 1) β Bool => hashBool u x = a), hashBool_fiber_card x hx] | |
| have hc : (Fintype.card (Fin (d + r - 1) β Bool) : β) = | |
| (2 : β) ^ (d + r - 1) := by simp [] | |
| rw [hc] | |
| simp only [Nat.cast_pow, Nat.cast_ofNat] | |
| simpa only [one_mul, one_div] using normalize_hash_count (r := r) hd 1 | |
| theorem hashBool_collision_probability (x y : Fin d β Bool) (hxy : x β y) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => hashBool u x = hashBool u y) = | |
| ((2 : β) ^ r)β»ΒΉ := by | |
| have hd : 0 < d := by | |
| by_contra h | |
| have hd0 : d = 0 := by omega | |
| subst d | |
| exact hxy (Subsingleton.elim _ _) | |
| rw [finiteProb_eq_card_div_decidable | |
| (fun u : Fin (d + r - 1) β Bool => hashBool u x = hashBool u y), | |
| hashBool_collision_card x y hxy] | |
| have hc : (Fintype.card (Fin (d + r - 1) β Bool) : β) = | |
| (2 : β) ^ (d + r - 1) := by simp [] | |
| rw [hc] | |
| simp only [Nat.cast_pow, Nat.cast_ofNat] | |
| simpa only [one_mul, one_div] using normalize_hash_count (r := r) hd 1 | |
| theorem hashBool_badSeed_probability_le (T : Finset (Fin d)) | |
| (rho : {i : Fin d // i β T} β Bool) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)) β€ | |
| ((2 : β) ^ T.card - 1) / (2 : β) ^ r := by | |
| by_cases hd0 : d = 0 | |
| Β· subst d | |
| have hT : T = β := by | |
| ext i | |
| exact Fin.elim0 i | |
| have hinj (u : Fin (0 + r - 1) β Bool) : | |
| Set.InjOn (hashBool u) (boolCoordinateCube T rho) := by | |
| intro x hx y hy hxy | |
| exact Subsingleton.elim _ _ | |
| simp [finiteProb, hinj, hT] | |
| have hd : 0 < d := Nat.pos_of_ne_zero hd0 | |
| have hcount := hashBool_badSeed_card_le (r := r) T rho | |
| have hcast : | |
| (Fintype.card {u : Fin (d + r - 1) β Bool // | |
| Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)} : β) β€ | |
| ((2 : β) ^ T.card - 1 : β) * (2 : β) ^ (d - 1) := by | |
| exact_mod_cast hcount | |
| have hpow : 1 β€ (2 : β) ^ T.card := by | |
| have hp : 0 < (2 : β) ^ T.card := pow_pos (by decide) _ | |
| omega | |
| have hsub : (((2 : β) ^ T.card - 1 : β) : β) = | |
| (2 : β) ^ T.card - 1 := by | |
| rw [Nat.cast_sub hpow] | |
| simp | |
| have hc : (Fintype.card (Fin (d + r - 1) β Bool) : β) = | |
| (2 : β) ^ (d + r - 1) := by simp [] | |
| rw [hsub] at hcast | |
| rw [finiteProb_eq_card_div_decidable | |
| (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)), hc] | |
| calc | |
| _ β€ (((2 : β) ^ T.card - 1) * (2 : β) ^ (d - 1)) / | |
| (2 : β) ^ (d + r - 1) := | |
| div_le_div_of_nonneg_right hcast (by positivity) | |
| _ = _ := normalize_hash_count hd _ | |
| theorem hashBool_badSeed_probability_le_pow (T : Finset (Fin d)) | |
| (rho : {i : Fin d // i β T} β Bool) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Set.InjOn (hashBool u) (boolCoordinateCube T rho)) β€ | |
| (2 : β) ^ T.card / (2 : β) ^ r := by | |
| exact (hashBool_badSeed_probability_le T rho).trans | |
| (div_le_div_of_nonneg_right (by linarith) (by positivity)) | |
| def restrictionFixed (Ο : Restriction (Fin d)) : | |
| {i : Fin d // i β liveSet Ο} β Bool := | |
| fun i => (Ο i.val).getD false | |
| theorem fill_mem_boolCoordinateCube (Ο : Restriction (Fin d)) (z : Cube (Live Ο)) : | |
| fill Ο z β boolCoordinateCube (liveSet Ο) (restrictionFixed Ο) := by | |
| intro i hi | |
| have hn : Ο i β none := fun h => hi ((mem_liveSet Ο i).mpr h) | |
| simp [fill, hn, restrictionFixed] | |
| theorem range_fill_eq_boolCoordinateCube (Ο : Restriction (Fin d)) : | |
| Set.range (fill Ο) = boolCoordinateCube (liveSet Ο) (restrictionFixed Ο) := by | |
| ext x | |
| constructor | |
| Β· rintro β¨z, rflβ© | |
| exact fill_mem_boolCoordinateCube Ο z | |
| Β· intro hx | |
| refine β¨fun v => x v.val, ?_β© | |
| funext i | |
| by_cases hi : Ο i = none | |
| Β· simp [fill, hi] | |
| Β· have hnot : i β liveSet Ο := fun h => hi ((mem_liveSet Ο i).mp h) | |
| simpa [fill, hi, restrictionFixed] using (hx i hnot).symm | |
| theorem fill_injective (Ο : Restriction (Fin d)) : Function.Injective (fill Ο) := by | |
| intro z w h | |
| funext v | |
| simpa only [fill_live] using congrFun h v.val | |
| theorem hashBool_fill_injective_iff (Ο : Restriction (Fin d)) | |
| (u : Fin (d + r - 1) β Bool) : | |
| Function.Injective (fun z : Cube (Live Ο) => hashBool u (fill Ο z)) β | |
| Set.InjOn (hashBool u) (boolCoordinateCube (liveSet Ο) (restrictionFixed Ο)) := by | |
| constructor | |
| Β· intro h x hx y hy hxy | |
| rw [β range_fill_eq_boolCoordinateCube] at hx hy | |
| obtain β¨z, rflβ© := hx | |
| obtain β¨w, rflβ© := hy | |
| exact congrArg (fill Ο) (h hxy) | |
| Β· intro h z w hzw | |
| apply fill_injective Ο | |
| exact h (fill_mem_boolCoordinateCube Ο z) (fill_mem_boolCoordinateCube Ο w) hzw | |
| theorem card_liveSet (Ο : Restriction (Fin d)) : | |
| (liveSet Ο).card = Fintype.card (Live Ο) := by | |
| let e : Live Ο β β₯(liveSet Ο) := | |
| Equiv.subtypeEquivRight (fun i => (mem_liveSet Ο i).symm) | |
| exact ((Fintype.card_congr e).trans (Fintype.card_coe (liveSet Ο))).symm | |
| theorem hashBool_restriction_failure_le (Ο : Restriction (Fin d)) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Function.Injective (fun z : Cube (Live Ο) => hashBool u (fill Ο z))) β€ | |
| ((2 : β) ^ Fintype.card (Live Ο) - 1) / (2 : β) ^ r := by | |
| have he : finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Function.Injective (fun z : Cube (Live Ο) => hashBool u (fill Ο z))) = | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Set.InjOn (hashBool u) (boolCoordinateCube (liveSet Ο) (restrictionFixed Ο))) := by | |
| apply finiteAvg_congr | |
| intro u | |
| by_cases h : Set.InjOn (hashBool u) (boolCoordinateCube (liveSet Ο) (restrictionFixed Ο)) | |
| Β· have h' := (hashBool_fill_injective_iff Ο u).mpr h | |
| simp [h, h'] | |
| Β· have h' := mt (hashBool_fill_injective_iff Ο u).mp h | |
| simp [h, h'] | |
| rw [he] | |
| simpa only [card_liveSet] using | |
| hashBool_badSeed_probability_le (r := r) (liveSet Ο) (restrictionFixed Ο) | |
| theorem hashBool_restriction_failure_le_pow (Ο : Restriction (Fin d)) : | |
| finiteProb (fun u : Fin (d + r - 1) β Bool => | |
| Β¬ Function.Injective (fun z : Cube (Live Ο) => hashBool u (fill Ο z))) β€ | |
| (2 : β) ^ Fintype.card (Live Ο) / (2 : β) ^ r := by | |
| exact (hashBool_restriction_failure_le Ο).trans | |
| (div_le_div_of_nonneg_right (by linarith) (by positivity)) | |
| end BinaryHash | |
| end DepthThreeLowerBound | |
| end | |
| end OAI | |