Download data/lean/OAI/Dynamics/ConditionalShuffle/HybridPrefix.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Dynamics/ConditionalShuffle/HybridPrefix.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Dynamics/ConditionalShuffle/HybridPrefix.lean
-
curl -L -o HybridPrefix.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Dynamics/ConditionalShuffle/HybridPrefix.lean
11.3 kB
| import OAI.Dynamics.ConditionalShuffle.HybridRaw | |
| namespace OAI | |
| noncomputable section | |
| open scoped Classical | |
| namespace Thorp.Conditional.Hybrid | |
| open Revealed.Split Revealed.Disintegration | |
| abbrev Public (d t : β) := Fin t β Option (Coins d) | |
| def energy (d : β) (v : RawState (d+1)) (t : β) (s : Fin t β Bool) : β := | |
| mean (fun Ο : History (d+1) t => rawEnergy (raw d v t s Ο)) | |
| lemma tagged_deviation {ΞΉ : Type*} (d : β) | |
| (B : Position (d+1) β Bool) (tag : Position (d+1)) (ht : B tag = true) | |
| (e : ΞΉ β Position (d+1)) (he : β i, B (e i) = false) (t : β) (s : Fin t β Bool) | |
| (f : Public (d+1) t β (Fin (t+1) β ΞΉ β Position (d+1)) β Position (d+1) β β) | |
| (hf : β q p y, |f q p y| β€ 1) : | |
| |mean (fun Ο : History (d+1) t => | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) (run (d+1) t Ο tag) - | |
| (1 / (freeCount B : β)) * β y, if B ((run (d+1) t Ο).symm y) then | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) y else 0)| β€ | |
| Real.sqrt ((Fintype.card (Position (d+1)) : β) * | |
| energy d (initialState (d+1) B tag ht).raw t s) := by | |
| have hh := flow_joint d (initialState (d+1) B tag ht).raw e he t s f | |
| have hl : mean (fun Ο : History (d+1) t => | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) (run (d+1) t Ο tag) - | |
| (1 / (freeCount B : β)) * β y, if B ((run (d+1) t Ο).symm y) then | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) y else 0) = | |
| mean (fun Ο : History (d+1) t => β x, (initialState (d+1) B tag ht).raw.weight x * | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) (run (d+1) t Ο x)) := by | |
| apply mean_congr; intro Ο | |
| change _ = β x, centeredPoint B tag x * | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) (run (d+1) t Ο x) | |
| rw [centeredPoint_test] | |
| congr 2 | |
| simpa only [Equiv.symm_apply_apply] using | |
| (Equiv.sum_comp (run (d+1) t Ο) (fun y => if B ((run (d+1) t Ο).symm y) then | |
| f (publicHistory s Ο) (exposedPath (d+1) e t Ο) y else 0)).symm | |
| rw [hl, hh] | |
| exact mean_weighted_test_le _ _ (fun Ο y => hf _ _ _) | |
| lemma completion_error {ΞΉ Ξ± : Type*} [Fintype ΞΉ] [Fintype Ξ±] [DecidableEq Ξ±] | |
| (d : β) (L : Sum ΞΉ Ξ± β Position (d+1)) {k : β} (e : Fin k β Ξ±) | |
| (tag : Ξ±) (ht : freeOf e tag = true) (t : β) (s : Fin t β Bool) | |
| (f : Public (d+1) t β (Fin (t+1) β ΞΉ β Position (d+1)) β (Fin (k+1) β Position (d+1)) β β) | |
| (hf : β q p z, |f q p z| β€ 1) : | |
| |mean (fun Ο : History (d+1) t => | |
| f (publicHistory s Ο) (splitPath L t Ο) (splitTuple L t Ο (Fin.snoc e tag))) - | |
| mean (fun Ο : History (d+1) t => | |
| pathComplete (f (publicHistory s Ο)) (splitPath L t Ο) (splitTuple L t Ο e))| β€ | |
| Real.sqrt ((Fintype.card (Position (d+1)) : β) * energy d | |
| (initialState (d+1) (avoid (Sum.elim (fun i => L (.inl i)) (fun j => L (.inr (e j))))) | |
| (L (.inr tag)) (by rwa [avoid_equiv_right])).raw t s) := by | |
| let z : Sum ΞΉ (Fin k) β Position (d+1) := | |
| Sum.elim (fun i => L (.inl i)) (fun j => L (.inr (e j))) | |
| let B := avoid z | |
| let F (q : Public (d+1) t) (p : Fin (t+1) β Sum ΞΉ (Fin k) β Position (d+1)) (y : Position (d+1)) := | |
| f q (fun a i => p a (.inl i)) (Fin.snoc (fun j => p (Fin.last t) (.inr j)) y) | |
| have hh := tagged_deviation d B (L (.inr tag)) ((avoid_equiv_right L e tag).trans ht) | |
| z (avoid_exposed z) t s F (fun q p y => hf _ _ _) | |
| have ho (Ο : History (d+1) t) : | |
| (fun a i => exposedPath (d+1) z t Ο a (.inl i)) = splitPath L t Ο := | |
| exposedPath_comp (d+1) z Sum.inl t Ο | |
| have he (Ο : History (d+1) t) : | |
| (fun j => exposedPath (d+1) z t Ο (Fin.last t) (.inr j)) = splitTuple L t Ο e := by | |
| rw [exposedPath_last]; rfl | |
| have hF (q) (Ο : History (d+1) t) (y : Position (d+1)) : | |
| F q (exposedPath (d+1) z t Ο) y = f q (splitPath L t Ο) (Fin.snoc (splitTuple L t Ο e) y) := by | |
| change f _ _ _ = _; rw [ho, he] | |
| have hB (Ο : History (d+1) t) (y : Position (d+1)) : | |
| B ((run (d+1) t Ο).symm y) = | |
| avoid (Sum.elim (splitPath L t Ο (Fin.last t)) (splitTuple L t Ο e)) y := by | |
| rw [splitPath_last] | |
| have hz : Sum.elim (fun i => run (d+1) t Ο (L (.inl i))) (splitTuple L t Ο e) = | |
| (run (d+1) t Ο) β z := by funext i; cases i <;> rfl | |
| rw [hz]; exact (avoid_perm z (run (d+1) t Ο) y).symm | |
| have hcount (Ο : History (d+1) t) : | |
| freeCount (avoid (Sum.elim (splitPath L t Ο (Fin.last t)) (splitTuple L t Ο e))) = freeCount B := by | |
| rw [splitPath_last] | |
| change freeCount (avoid (Sum.elim (fun i => (L.trans (run (d+1) t Ο)) (.inl i)) | |
| (fun j => (L.trans (run (d+1) t Ο)) (.inr (e j))))) = _ | |
| rw [freeCount_avoid_equiv, show freeCount B = freeCount (freeOf e) from freeCount_avoid_equiv L e] | |
| simp_rw [hF, hB] at hh | |
| rw [β mean_sub] | |
| convert hh using 1 | |
| congr 1 | |
| apply mean_congr; intro Ο | |
| rw [splitTuple_snoc] | |
| congr 1 | |
| exact congrArg (fun n : β => (1/(n : β)) * β y, | |
| if avoid (Sum.elim (splitPath L t Ο (Fin.last t)) (splitTuple L t Ο e)) y then | |
| f (publicHistory s Ο) (splitPath L t Ο) (Fin.snoc (splitTuple L t Ο e) y) else 0) (hcount Ο) | |
| theorem tuple_test {ΞΉ Ξ± : Type*} [Fintype ΞΉ] [Fintype Ξ±] [DecidableEq Ξ±] | |
| (d t m : β) (s : Fin t β Bool) (Ξ΅ : β) | |
| (hE : β (B : Position (d+1) β Bool) (tag) (ht : B tag = true), | |
| m β€ freeCount B β freeCount B β€ Fintype.card Ξ± β | |
| energy d (initialState (d+1) B tag ht).raw t s β€ Ξ΅) | |
| (L : Sum ΞΉ Ξ± β Position (d+1)) (k : β) (hk : k+m β€ Fintype.card Ξ±) | |
| (e : Fin k β Ξ±) (he : Function.Injective e) | |
| (f : Public (d+1) t β (Fin (t+1) β ΞΉ β Position (d+1)) β (Fin k β Position (d+1)) β β) | |
| (hf : β q p z, |f q p z| β€ 1) : | |
| |mean (fun Ο : History (d+1) t => f (publicHistory s Ο) (splitPath L t Ο) (splitTuple L t Ο e)) - | |
| mean (fun Ο : History (d+1) t => mean (fun Ο : Equiv.Perm Ξ± => | |
| f (publicHistory s Ο) (splitPath L t Ο) (splitTuple L t Ο (Ο β e))))| β€ | |
| (k : β) * Real.sqrt ((Fintype.card (Position (d+1)) : β) * Ξ΅) := by | |
| induction k with | |
| | zero => | |
| have hz (Ο : History (d+1) t) (Ο : Equiv.Perm Ξ±) : | |
| splitTuple L t Ο (Ο β e) = splitTuple L t Ο e := Subsingleton.elim _ _ | |
| simp_rw [hz, mean_const] | |
| simp | |
| | succ k ih => | |
| have he0 : Function.Injective (Fin.init e) := by | |
| intro i j hij; exact Fin.castSucc_inj.mp (he hij) | |
| have ht : freeOf (Fin.init e) (e (Fin.last k)) = true := by | |
| apply (freeOf_true _ _).mpr; intro i hi | |
| exact Fin.castSucc_ne_last i (he hi) | |
| let B := avoid (Sum.elim (fun i => L (.inl i)) (fun j => L (.inr (Fin.init e j)))) | |
| have htag : B (L (.inr (e (Fin.last k)))) = true := (avoid_equiv_right _ _ _).trans ht | |
| have hcount : freeCount B = Fintype.card Ξ± - k := by | |
| rw [show freeCount B = freeCount (freeOf (Fin.init e)) from freeCount_avoid_equiv L (Fin.init e), | |
| freeCount_freeOf _ he0] | |
| have henergy := hE B _ htag (by omega) (by omega) | |
| have hz := completion_error d L (Fin.init e) (e (Fin.last k)) ht t s f hf | |
| rw [Fin.snoc_init_self] at hz | |
| have hestimate : Real.sqrt ((Fintype.card (Position (d+1)) : β) * | |
| energy d (initialState (d+1) B (L (.inr (e (Fin.last k)))) htag).raw t s) β€ | |
| Real.sqrt ((Fintype.card (Position (d+1)) : β) * Ξ΅) := | |
| Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_left henergy (Nat.cast_nonneg _)) | |
| have hnext := ih (by omega) (Fin.init e) he0 | |
| (fun q => pathComplete (f q)) (fun q => pathComplete_bound (f q) (hf q)) | |
| have hu (Ο : History (d+1) t) := uniform_splitTuple_completion L e he t Ο (f (publicHistory s Ο)) | |
| simp_rw [hu] | |
| have htri := abs_sub_le | |
| (mean (fun Ο : History (d+1) t => f (publicHistory s Ο) (splitPath L t Ο) (splitTuple L t Ο e))) | |
| (mean (fun Ο : History (d+1) t => pathComplete (f (publicHistory s Ο)) (splitPath L t Ο) | |
| (splitTuple L t Ο (Fin.init e)))) | |
| (mean (fun Ο : History (d+1) t => mean (fun Ο : Equiv.Perm Ξ± => | |
| pathComplete (f (publicHistory s Ο)) (splitPath L t Ο) (splitTuple L t Ο (Ο β Fin.init e))))) | |
| have hz' := hz.trans hestimate | |
| push_cast | |
| nlinarith | |
| lemma assignment_test {ΞΉ Ξ± : Type*} [Fintype ΞΉ] [Fintype Ξ±] [DecidableEq Ξ±] [Nonempty Ξ±] | |
| (d t m : β) (s : Fin t β Bool) (Ξ΅ : β) | |
| (hE : β (B : Position (d+1) β Bool) (tag) (ht : B tag = true), | |
| m β€ freeCount B β freeCount B β€ Fintype.card Ξ± β | |
| energy d (initialState (d+1) B tag ht).raw t s β€ Ξ΅) | |
| (L : Sum ΞΉ Ξ± β Position (d+1)) (k : β) (hk : k+m β€ Fintype.card Ξ±) | |
| (e : Fin k β Ξ±) (he : Function.Injective e) | |
| (f : Public (d+1) t β (Fin (t+1) β ΞΉ β Position (d+1)) β (Fin k β Ξ±) β β) | |
| (hf : β q p z, |f q p z| β€ 1) : | |
| |mean (fun Ο : History (d+1) t => f (publicHistory s Ο) (splitPath L t Ο) | |
| (assignment (L.trans (run (d+1) t Ο)) β e)) - | |
| mean (fun Ο : History (d+1) t => mean (fun Ο : Equiv.Perm Ξ± => | |
| f (publicHistory s Ο) (splitPath L t Ο) (Ο β e)))| β€ | |
| (k : β) * Real.sqrt ((Fintype.card (Position (d+1)) : β) * Ξ΅) := by | |
| let F (q : Public (d+1) t) (p : Fin (t+1) β ΞΉ β Position (d+1)) (z : Fin k β Position (d+1)) := | |
| f q p (fun j => indexRight (frameFor L (p (Fin.last t))) (z j)) | |
| have hh := tuple_test d t m s Ξ΅ hE L k hk e he F (fun q p z => hf _ _ _) | |
| have hF (Ο : History (d+1) t) (a : Fin k β Ξ±) : | |
| F (publicHistory s Ο) (splitPath L t Ο) (splitTuple L t Ο a) = | |
| f (publicHistory s Ο) (splitPath L t Ο) (assignment (L.trans (run (d+1) t Ο)) β a) := by | |
| dsimp only [F, splitTuple] | |
| rw [splitPath_last, indexRight_tuple] | |
| simp_rw [hF] at hh | |
| have hu (Ο : History (d+1) t) := mean_perm_comp (assignment (L.trans (run (d+1) t Ο))) | |
| e (f (publicHistory s Ο) (splitPath L t Ο)) | |
| simp_rw [hu] at hh | |
| exact hh | |
| lemma marginal_bound {ΞΉ Ξ± : Type*} [Fintype ΞΉ] [Fintype Ξ±] [DecidableEq Ξ±] [Nonempty Ξ±] | |
| (d t m : β) (s : Fin t β Bool) (Ξ΅ : β) | |
| (hE : β (B : Position (d+1) β Bool) (tag) (ht : B tag = true), | |
| m β€ freeCount B β freeCount B β€ Fintype.card Ξ± β | |
| energy d (initialState (d+1) B tag ht).raw t s β€ Ξ΅) | |
| (L : Sum ΞΉ Ξ± β Position (d+1)) (k : β) (hk : k+m β€ Fintype.card Ξ±) | |
| (e : Fin k β Ξ±) (he : Function.Injective e) : | |
| let ΞΌ := fairMass (fun Ο : History (d+1) t => | |
| ((publicHistory s Ο, splitPath L t Ο), assignment (L.trans (run (d+1) t Ο)))) | |
| (β p, marginal ΞΌ p * tv (Trim.push (conditional ΞΌ p) (fun g : Equiv.Perm Ξ± => g β e)) | |
| (fairMass (fun g : Equiv.Perm Ξ± => g β e))) β€ | |
| (k : β) / 2 * Real.sqrt ((Fintype.card (Position (d+1)) : β) * Ξ΅) := by | |
| have hh := conditional_projection_le_of_test | |
| (fun Ο : History (d+1) t => (publicHistory s Ο, splitPath L t Ο)) | |
| (fun Ο : History (d+1) t => assignment (L.trans (run (d+1) t Ο))) | |
| (fun g : Equiv.Perm Ξ± => g β e) ((k : β) * Real.sqrt ((Fintype.card (Position (d+1)) : β) * Ξ΅)) | |
| (fun f hf => assignment_test d t m s Ξ΅ hE L k hk e he | |
| (fun q p z => f ((q,p),z)) (fun q p z => hf _)) | |
| exact hh.trans_eq (by ring) | |
| end Thorp.Conditional.Hybrid | |
| end | |
| end OAI | |