Download data/lean/OAI/Computability/DirectedFeedback/RankGraph/FailureEvent.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 44.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/RankGraph/FailureEvent.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/DirectedFeedback/RankGraph/FailureEvent.lean
-
curl -L -o FailureEvent.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/RankGraph/FailureEvent.lean
44.1 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.RankGraph.Bias | |
| namespace OAI | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical | |
| noncomputable section | |
| open scoped Classical | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped BigOperators | |
| noncomputable section | |
| open scoped BigOperators | |
| open DirectedFeedback.SourceProbability | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| namespace DirectedFeedback.Construction | |
| open DirectedFeedback.SourceProbability FiniteDistribution | |
| open RankGraph Prefix PrefixExperiment Games Pivotal | |
| variable {U V E X Y : Type} [Fintype U] [Fintype V] [Fintype E] | |
| [Fintype X] [Fintype Y] [Nonempty X] [Nonempty Y] | |
| variable {M T N : β} [NeZero M] [NeZero T] | |
| variable (G : Game U V E X Y) (ΟLaw : FiniteDistribution (Emb (rankLength X T) N)) | |
| variable (hYX : Fintype.card Y β€ Fintype.card X) (fiber : E β X β Y Γ Bool) | |
| variable (deleted : OutputVertex (M := M) G ΟLaw β Bool) | |
| variable (ord : OutputVertex (M := M) G ΟLaw β β) | |
| variable (hord : β {a b}, deleted a = false β deleted b = false β | |
| OutputArc G ΟLaw hYX fiber a b β ord a < ord b) | |
| variable (hrank : β r, deleted (.inl r) = false) | |
| theorem bigFunction_properties (fallback : X) (d : Common U X M T N) (u : U) : | |
| Monotone (bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d u) β§ | |
| bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d u (fun _ => false) = false β§ | |
| bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d u (fun _ => true) = true := by | |
| obtain β¨hm,h0,h1β© := conditionedBig_properties (rankOrder G ΟLaw ord) d.1.val rankLength_ge | |
| d.1.property (rankOrder_arc G ΟLaw hYX fiber deleted ord hord hrank) | |
| d.2.1 (vertices d.2.2) (cell d.2.2) u fallback | |
| exact subset_function_properties _ hm h0 h1 | |
| theorem smallFunction_properties (fallback : Y) (d : Common U X M T N) (v : V) : | |
| Monotone (smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d v) β§ | |
| smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d v (fun _ => false) = false β§ | |
| smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallback d v (fun _ => true) = true := by | |
| obtain β¨hm,h0,h1β© := conditionedSmall_properties (rankOrder G ΟLaw ord) d.1.val rankLength_ge | |
| d.1.property (rankOrder_arc G ΟLaw hYX fiber deleted ord hord hrank) | |
| d.2.1 (vertices d.2.2) (cell d.2.2) v fallback | |
| exact subset_function_properties _ hm h0 h1 | |
| theorem family_costs (D H K : β) (hD : 0 β€ D) (hH : 0 β€ H) (hK : 0 β€ K) | |
| (hcost : totalDeletionCost G ΟLaw D H K deleted β€ D) : | |
| H * (fullLaw G ΟLaw).probability (fullDeleted G ΟLaw deleted) β€ D β§ | |
| Fintype.card X * (bigLaw G ΟLaw).probability (bigDeleted G ΟLaw deleted) β€ D β§ | |
| Fintype.card Y * (smallLaw G ΟLaw).probability (smallDeleted G ΟLaw deleted) β€ D β§ | |
| K * (comparisonLaw G ΟLaw).probability (comparisonDeleted G ΟLaw deleted) β€ D := by | |
| rw [deletionCost_decomposition] at hcost | |
| have hr : 0 β€ β r : Rank U V X Y T N, if deleted (.inl r) then D+1 else 0 := by | |
| apply Finset.sum_nonneg | |
| intro r _ | |
| split <;> linarith | |
| have hf := mul_nonneg hH (probability_nonnegative (fullLaw G ΟLaw) (fullDeleted G ΟLaw deleted)) | |
| have hb := mul_nonneg (Nat.cast_nonneg (Fintype.card X) : (0:β) β€ Fintype.card X) | |
| (probability_nonnegative (bigLaw G ΟLaw) (bigDeleted G ΟLaw deleted)) | |
| have hs := mul_nonneg (Nat.cast_nonneg (Fintype.card Y) : (0:β) β€ Fintype.card Y) | |
| (probability_nonnegative (smallLaw G ΟLaw) (smallDeleted G ΟLaw deleted)) | |
| have hc := mul_nonneg hK (probability_nonnegative (comparisonLaw G ΟLaw) (comparisonDeleted G ΟLaw deleted)) | |
| exact β¨by linarith, by linarith, by linarith, by linarithβ© | |
| theorem big_budget (fallback : X) (D Ο : β) (hΟ : Fintype.card X * Ο β€ 1) | |
| (hbad : ((common (M := M) G ΟLaw).product (bigMarginal G)).probability | |
| (fun a => decide (Β¬bigGood G ΟLaw ord a.1 a.2)) β€ Ο) | |
| (hcost : Fintype.card X * (bigLaw G ΟLaw).probability (bigDeleted G ΟLaw deleted) β€ D) : | |
| ((common (M := M) G ΟLaw).product (bigMarginal G)).expectation | |
| (fun a => budget (bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallback a.1 a.2)) β€ D+1 := by | |
| apply averaged_budget_charge_support _ _ (fun a => decide (bigGood G ΟLaw ord a.1 a.2)) | |
| (fun a o => bigDeleted G ΟLaw deleted (a.1,(a.2,o))) D Ο hΟ | |
| Β· simpa using hbad | |
| Β· simpa only [bigLaw, probability_eq_expect, expectation_product] using hcost | |
| Β· intro a ha hg o hh | |
| have hd : 0 < (bigLaw G ΟLaw).weight (a.1,(a.2,o)) := by | |
| change 0 < (common G ΟLaw).weight a.1 * ((bigMarginal G).weight a.2 * labelOrderLaw.weight o) | |
| rw [β mul_assoc] | |
| exact mul_pos ha (labelOrder_weight_pos o) | |
| change (bigLaw G ΟLaw).extend _ _ = true | |
| rw [show (a.1,(a.2,o)) = (β¨(a.1,(a.2,o)),hdβ© : (bigLaw G ΟLaw).Support).val from rfl, | |
| extend_at_support] | |
| exact big_forces_deletion G ΟLaw hYX fiber deleted ord hord hrank _ fallback | |
| (of_decide_eq_true hg) hh | |
| theorem small_budget (fallback : Y) (D Ο : β) (hΟ : Fintype.card Y * Ο β€ 1) | |
| (hbad : ((common (M := M) G ΟLaw).product (smallMarginal G)).probability | |
| (fun a => decide (Β¬smallGood G ΟLaw ord a.1 a.2)) β€ Ο) | |
| (hcost : Fintype.card Y * (smallLaw G ΟLaw).probability (smallDeleted G ΟLaw deleted) β€ D) : | |
| ((common (M := M) G ΟLaw).product (smallMarginal G)).expectation | |
| (fun a => budget (smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallback a.1 a.2)) β€ D+1 := by | |
| apply averaged_budget_charge_support _ _ (fun a => decide (smallGood G ΟLaw ord a.1 a.2)) | |
| (fun a o => smallDeleted G ΟLaw deleted (a.1,(a.2,o))) D Ο hΟ | |
| Β· simpa using hbad | |
| Β· simpa only [smallLaw, probability_eq_expect, expectation_product] using hcost | |
| Β· intro a ha hg o hh | |
| have hd : 0 < (smallLaw G ΟLaw).weight (a.1,(a.2,o)) := by | |
| change 0 < (common G ΟLaw).weight a.1 * ((smallMarginal G).weight a.2 * labelOrderLaw.weight o) | |
| rw [β mul_assoc] | |
| exact mul_pos ha (labelOrder_weight_pos o) | |
| change (smallLaw G ΟLaw).extend _ _ = true | |
| rw [show (a.1,(a.2,o)) = (β¨(a.1,(a.2,o)),hdβ© : (smallLaw G ΟLaw).Support).val from rfl, | |
| extend_at_support] | |
| exact small_forces_deletion G ΟLaw hYX fiber deleted ord hord hrank _ fallback | |
| (of_decide_eq_true hg) hh | |
| end DirectedFeedback.Construction | |
| noncomputable section | |
| open scoped Classical BigOperators | |
| namespace DirectedFeedback.SourceProbability.FiniteDistribution | |
| variable {I Z : Type*} [Fintype I] [Nonempty I] [Fintype Z] | |
| theorem uniform_single_le (f : I β β) (hf : β i, 0 β€ f i) (i : I) : | |
| f i β€ Fintype.card I * (uniform I).expectation f := by | |
| have hc : (Fintype.card I : β) β 0 := by exact_mod_cast Fintype.card_ne_zero | |
| have he : (Fintype.card I : β) * (uniform I).expectation f = β j, f j := by | |
| rw [expectation_uniform] | |
| field_simp | |
| rw [he] | |
| exact Finset.single_le_sum (fun j _ => hf j) (Finset.mem_univ i) | |
| theorem fixed_choice_charge (ΞΌ : FiniteDistribution Z) (event : Z β Bool) | |
| (deleted : I β Z β Bool) (i : I) | |
| (hforce : β z, 0 < ΞΌ.weight z β event z = true β deleted i z = true) : | |
| ΞΌ.probability event β€ Fintype.card I * ((uniform I).product ΞΌ).probability | |
| (fun a => deleted a.1 a.2) := by | |
| have h := probability_mono_support ΞΌ hforce | |
| have he : ((uniform I).product ΞΌ).probability (fun a => deleted a.1 a.2) = | |
| (uniform I).expectation (fun i => ΞΌ.probability (deleted i)) := by | |
| simp only [probability_eq_expect, expectation_product] | |
| rw [he] | |
| exact h.trans (uniform_single_le _ (fun j => probability_nonnegative ΞΌ (deleted j)) i) | |
| omit [Fintype I] [Nonempty I] in | |
| theorem probability_good_restrict (ΞΌ : FiniteDistribution Z) (event : Z β Bool) (P Q : Prop) : | |
| ΞΌ.probability event β€ ΞΌ.probability (fun z => decide (P β§ Q) && event z) + | |
| (if Β¬P then 1 else 0) + (if Β¬Q then 1 else 0) := by | |
| have h := probability_le_one ΞΌ event | |
| rw [probability_eq_expect] at h | |
| by_cases hP : P <;> by_cases hQ : Q <;> simp [hP,hQ] <;> linarith | |
| end DirectedFeedback.SourceProbability.FiniteDistribution | |
| namespace DirectedFeedback.Construction | |
| open DirectedFeedback.SourceProbability FiniteDistribution | |
| open RankGraph Prefix PrefixExperiment Games | |
| variable {U V E X Y : Type} [Fintype U] [Fintype V] [Fintype E] | |
| [Fintype X] [Fintype Y] [Nonempty X] [Nonempty Y] | |
| variable {M T N : β} [NeZero M] [NeZero T] | |
| variable (G : Game U V E X Y) (ΟLaw : FiniteDistribution (Emb (rankLength X T) N)) | |
| variable (hYX : Fintype.card Y β€ Fintype.card X) (fiber : E β X β Y Γ Bool) | |
| variable (deleted : OutputVertex (M := M) G ΟLaw β Bool) | |
| variable (ord : OutputVertex (M := M) G ΟLaw β β) | |
| variable (hord : β {a b}, deleted a = false β deleted b = false β | |
| OutputArc G ΟLaw hYX fiber a b β ord a < ord b) | |
| variable (hrank : β r, deleted (.inl r) = false) | |
| def failureEvent (fallbackX : X) (fallbackY : Y) (a : Common U X M T N Γ E) | |
| (z : Y β Coupling.Block) : Bool := | |
| bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallbackX a.1 (G.left a.2) | |
| (Coupling.bigBits (fiber a.2) z) && | |
| !(smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallbackY a.1 (G.right a.2) | |
| (Coupling.smallBits z)) | |
| def scaleDeletion (i : Fin M) (a : Common U X M T N Γ E) : β := | |
| ((uniform (Fin (cellCount a.1.2.1.val))).product | |
| (Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i]))).probability | |
| (fun q => comparisonDeleted G ΟLaw deleted β¨a.1,a.2,β¨i,qβ©β©) | |
| theorem scaleDeletion_nonneg (i : Fin M) (a : Common U X M T N Γ E) : | |
| 0 β€ scaleDeletion G ΟLaw deleted i a := probability_nonnegative _ _ | |
| theorem comparison_probability_decomposition : | |
| (comparisonLaw G ΟLaw).probability (comparisonDeleted G ΟLaw deleted) = | |
| ((common (M := M) G ΟLaw).product G.edgeLaw).expectation (fun a => | |
| (uniform (Fin M)).expectation (fun i => scaleDeletion G ΟLaw deleted i a)) := by | |
| simp only [comparisonLaw, scaleDeletion, probability_eq_expect, expectation_sigma, expectation_product] | |
| theorem single_scale_cost (i : Fin M) : | |
| ((common (M := M) G ΟLaw).product G.edgeLaw).expectation (scaleDeletion G ΟLaw deleted i) β€ | |
| M * (comparisonLaw G ΟLaw).probability (comparisonDeleted G ΟLaw deleted) := by | |
| rw [comparison_probability_decomposition, β expectation_mul_left] | |
| apply expectation_mono | |
| intro a | |
| simpa only [Fintype.card_fin] using uniform_single_le | |
| (fun j => scaleDeletion G ΟLaw deleted j a) (fun j => scaleDeletion_nonneg G ΟLaw deleted j a) i | |
| theorem good_failure_charge (fallbackX : X) (fallbackY : Y) (i : Fin M) | |
| (a : Common U X M T N Γ E) | |
| (ha : 0 < ((common (M := M) G ΟLaw).product G.edgeLaw).weight a) : | |
| (Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i])).probability | |
| (fun z => decide (bigGood G ΟLaw ord a.1 (G.left a.2) β§ | |
| smallGood G ΟLaw ord a.1 (G.right a.2)) && | |
| failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a z) β€ | |
| (2:β)^T * scaleDeletion G ΟLaw deleted i a := by | |
| let Ξ½ := Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i]) | |
| have hf := fixed_choice_charge Ξ½ | |
| (fun z => decide (bigGood G ΟLaw ord a.1 (G.left a.2) β§ smallGood G ΟLaw ord a.1 (G.right a.2)) && | |
| failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a z) | |
| (fun r z => comparisonDeleted G ΟLaw deleted β¨a.1,a.2,β¨i,r,zβ©β©) | |
| (commonTransition G ΟLaw hYX fiber deleted ord hord hrank a.1) (by | |
| intro z hz he | |
| let d : Compare U E X Y M T N := β¨a.1,a.2,β¨i,commonTransition G ΟLaw hYX fiber deleted ord hord hrank a.1,zβ©β© | |
| have hp : 0 < (comparisonLaw G ΟLaw).weight d := by | |
| have hp1 : 0 < (common G ΟLaw).weight a.1 := | |
| pos_of_mul_pos_left ha (G.edgeLaw.nonnegative a.2) | |
| have hp2 : 0 < G.edgeLaw.weight a.2 := | |
| pos_of_mul_pos_right ha ((common G ΟLaw).nonnegative a.1) | |
| simp only [d, comparisonLaw, sigma, product, uniform, Fintype.card_fin] | |
| change 0 < (common G ΟLaw).weight a.1 * (G.edgeLaw.weight a.2 * | |
| (1/(M:β) * (1/(cellCount a.1.2.1.val : β) * Ξ½.weight z))) | |
| have hM : (0:β) < M := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne M) | |
| have hcell : (0:β) < cellCount a.1.2.1.val := by | |
| exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne (cellCount a.1.2.1.val)) | |
| exact mul_pos hp1 (mul_pos hp2 (mul_pos (div_pos zero_lt_one hM) | |
| (mul_pos (div_pos zero_lt_one hcell) hz))) | |
| have he' : decide (bigGood G ΟLaw ord a.1 (G.left a.2) β§ | |
| smallGood G ΟLaw ord a.1 (G.right a.2)) = true β§ | |
| failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a z = true := by | |
| simpa only [Bool.and_eq_true] using he | |
| obtain β¨hg,heβ© := he' | |
| obtain β¨hgU,hgVβ© := of_decide_eq_true hg | |
| have he' : bigFunction G ΟLaw hYX fiber deleted ord hord hrank fallbackX a.1 (G.left a.2) | |
| (Coupling.bigBits (fiber a.2) z) = true β§ | |
| smallFunction G ΟLaw hYX fiber deleted ord hord hrank fallbackY a.1 (G.right a.2) | |
| (Coupling.smallBits z) = false := by | |
| simpa only [failureEvent, Bool.and_eq_true, Bool.not_eq_true'] using he | |
| obtain β¨hu,hvβ© := he' | |
| have hh := comparison_forces_deletion G ΟLaw hYX fiber deleted ord hord hrank β¨d,hpβ© | |
| fallbackX fallbackY hgU hgV rfl hu (by simpa using hv) | |
| change (comparisonLaw G ΟLaw).extend _ d = true | |
| rw [show d = (β¨d,hpβ© : (comparisonLaw G ΟLaw).Support).val from rfl, extend_at_support] | |
| exact hh) | |
| change _ β€ (2:β)^T * scaleDeletion G ΟLaw deleted i a | |
| apply hf.trans | |
| change (Fintype.card (Fin (cellCount a.1.2.1.val)) : β) * scaleDeletion G ΟLaw deleted i a β€ _ | |
| apply mul_le_mul_of_nonneg_right _ (scaleDeletion_nonneg G ΟLaw deleted i a) | |
| simp only [Fintype.card_fin, cellCount_eq, Nat.cast_pow, Nat.cast_ofNat] | |
| exact pow_le_pow_rightβ (by norm_num : (1:β) β€ 2) (Nat.le_of_lt a.1.2.1.isLt) | |
| theorem comparison_charge (fallbackX : X) (fallbackY : Y) (i : Fin M) | |
| (D K Ο : β) (hK : 0 < K) | |
| (hcost : K * (comparisonLaw G ΟLaw).probability (comparisonDeleted G ΟLaw deleted) β€ D) | |
| (hbU : ((common (M := M) G ΟLaw).product G.edgeLaw).probability (fun a => | |
| decide (Β¬bigGood G ΟLaw ord a.1 (G.left a.2))) β€ Ο) | |
| (hbV : ((common (M := M) G ΟLaw).product G.edgeLaw).probability (fun a => | |
| decide (Β¬smallGood G ΟLaw ord a.1 (G.right a.2))) β€ Ο) : | |
| ((common (M := M) G ΟLaw).product G.edgeLaw).expectation (fun a => | |
| (Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i])).probability | |
| (failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a)) β€ | |
| 2*Ο + M*(2:β)^T*D/K := by | |
| let ΞΌ := (common (M := M) G ΟLaw).product G.edgeLaw | |
| have hh := expectation_mono_support ΞΌ (f := fun a => | |
| (Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i])).probability | |
| (failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a)) | |
| (g := fun a => (2:β)^T * scaleDeletion G ΟLaw deleted i a + | |
| (if Β¬bigGood G ΟLaw ord a.1 (G.left a.2) then 1 else 0) + | |
| (if Β¬smallGood G ΟLaw ord a.1 (G.right a.2) then 1 else 0)) (by | |
| intro a ha | |
| have hp := probability_good_restrict | |
| (Coupling.law (Y := Y) (bias i) (bias_pos i).le (by linarith [bias_le_quarter i])) | |
| (failureEvent G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY a) | |
| (bigGood G ΟLaw ord a.1 (G.left a.2)) (smallGood G ΟLaw ord a.1 (G.right a.2)) | |
| have hc := good_failure_charge G ΟLaw hYX fiber deleted ord hord hrank fallbackX fallbackY i a ha | |
| linarith) | |
| rw [expectation_add, expectation_add, expectation_mul_left] at hh | |
| have hbi : ΞΌ.expectation (fun a => if Β¬bigGood G ΟLaw ord a.1 (G.left a.2) then 1 else 0) β€ Ο := by | |
| simpa only [probability_eq_expect, decide_eq_true_eq] using hbU | |
| have hsi : ΞΌ.expectation (fun a => if Β¬smallGood G ΟLaw ord a.1 (G.right a.2) then 1 else 0) β€ Ο := by | |
| simpa only [probability_eq_expect, decide_eq_true_eq] using hbV | |
| have hc : (comparisonLaw G ΟLaw).probability (comparisonDeleted G ΟLaw deleted) β€ D/K := | |
| (le_div_iffβ hK).mpr (by simpa [mul_comm] using hcost) | |
| have hs := (single_scale_cost G ΟLaw deleted i).trans | |
| (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg M)) | |
| have hmul := mul_le_mul_of_nonneg_left hs (show 0 β€ (2:β)^T by positivity) | |
| change _ β€ _ at hh | |
| have he : (2:β)^T * ((M:β) * (D/K)) = M*(2:β)^T*D/K := by ring | |
| rw [he] at hmul | |
| linarith | |
| end DirectedFeedback.Construction | |
| noncomputable section | |
| namespace DirectedFeedback.JuntaSupport | |
| open scoped BigOperators | |
| open Finset | |
| abbrev Cube (I : Type*) := I β Bool | |
| def bitSign (b : Bool) : β := if b then -1 else 1 | |
| @[simp] theorem bitSign_sq (b : Bool) : bitSign b ^ 2 = 1 := by | |
| cases b <;> norm_num [bitSign] | |
| theorem bitSign_xor (b c : Bool) : | |
| bitSign (b ^^ c) = bitSign b * bitSign c := by | |
| cases b <;> cases c <;> norm_num [bitSign] | |
| def cubeXor {I : Type*} (x y : Cube I) : Cube I := fun i => x i ^^ y i | |
| def walsh {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : β := | |
| β i, bitSign (s i && x i) | |
| theorem walsh_symm {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : | |
| walsh s x = walsh x s := by | |
| simp [walsh, Bool.and_comm] | |
| @[simp] theorem walsh_sq {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : | |
| walsh s x ^ 2 = 1 := by | |
| simp [walsh, β Finset.prod_pow] | |
| theorem walsh_xor {I : Type*} [Fintype I] [DecidableEq I] (s x y : Cube I) : | |
| walsh s (cubeXor x y) = walsh s x * walsh s y := by | |
| simp only [walsh, β Finset.prod_mul_distrib] | |
| apply Finset.prod_congr rfl | |
| intro i _ | |
| simp only [cubeXor] | |
| cases s i <;> cases x i <;> cases y i <;> norm_num [bitSign] | |
| theorem coordinate_orthogonality (s t : Bool) : | |
| (β x : Bool, bitSign (s && x) * bitSign (t && x)) = | |
| if s = t then 2 else 0 := by | |
| cases s <;> cases t <;> norm_num [bitSign, Fintype.sum_bool] | |
| theorem walsh_sum_orthogonality {I : Type*} [Fintype I] [DecidableEq I] | |
| (s t : Cube I) : | |
| (β x, walsh s x * walsh t x) = | |
| if s = t then (Fintype.card (Cube I) : β) else 0 := by | |
| classical | |
| simp only [walsh, β Finset.prod_mul_distrib] | |
| rw [β Fintype.prod_sum (fun (i : I) (b : Bool) => | |
| bitSign (s i && b) * bitSign (t i && b))] | |
| simp only [coordinate_orthogonality] | |
| by_cases h : s = t | |
| Β· subst t | |
| simp [] | |
| Β· rw [ite_eq_right h] | |
| obtain β¨i, hiβ© := Function.ne_iff.mp h | |
| apply Finset.prod_eq_zero (Finset.mem_univ i) | |
| exact ite_eq_right hi | |
| theorem walsh_orthogonality {I : Type*} [Fintype I] [DecidableEq I] | |
| (s t : Cube I) : | |
| (πΌ x, walsh s x * walsh t x) = if s = t then 1 else 0 := by | |
| classical | |
| rw [Fintype.expect_eq_sum_div_card, walsh_sum_orthogonality] | |
| split_ifs <;> simp | |
| def coefficient {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β β) (s : Cube I) : β := | |
| πΌ x, f x * walsh s x | |
| theorem walsh_inversion {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β β) (x : Cube I) : | |
| (β s, coefficient f s * walsh s x) = f x := by | |
| classical | |
| unfold coefficient | |
| simp_rw [Finset.expect_mul] | |
| rw [β Finset.expect_sum_comm] | |
| have h (y : Cube I) : | |
| (β s, (f y * walsh s y) * walsh s x) = | |
| f y * (if y = x then (Fintype.card (Cube I) : β) else 0) := by | |
| simp only [mul_assoc, β Finset.mul_sum] | |
| congr 1 | |
| simp_rw [walsh_symm (x := y), walsh_symm (x := x)] | |
| exact walsh_sum_orthogonality y x | |
| simp_rw [h] | |
| rw [Fintype.expect_eq_sum_div_card] | |
| simp | |
| theorem walsh_inner {I : Type*} [Fintype I] [DecidableEq I] (f g : Cube I β β) : | |
| (β s, coefficient f s * coefficient g s) = πΌ x, f x * g x := by | |
| classical | |
| unfold coefficient | |
| simp_rw [Finset.mul_expect] | |
| rw [β Finset.expect_sum_comm] | |
| apply Finset.expect_congr rfl | |
| intro x _ | |
| have h : (β s, (πΌ y, f y * walsh s y) * (g x * walsh s x)) = | |
| g x * (β s, coefficient f s * walsh s x) := by | |
| simp only [Finset.mul_sum, coefficient] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| ring | |
| rw [h, walsh_inversion] | |
| ring | |
| theorem walsh_parseval {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β β) : | |
| (β s, coefficient f s ^ 2) = πΌ x, f x ^ 2 := by | |
| simpa [pow_two] using walsh_inner f f | |
| theorem sign_parseval {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β Bool) : | |
| (β s, coefficient (fun x => bitSign (f x)) s ^ 2) = 1 := by | |
| rw [walsh_parseval] | |
| simp | |
| end DirectedFeedback.JuntaSupport | |
| namespace DFVSMaxCut.Analytic | |
| open Finset DirectedFeedback.JuntaSupport | |
| def degree {I : Type*} [Fintype I] (s : Cube I) : β := | |
| (Finset.univ.filter fun i => s i = true).card | |
| end DFVSMaxCut.Analytic | |
| namespace DFVSMaxCut.BooleanFourthMoment | |
| open scoped BigOperators | |
| open Finset DirectedFeedback.JuntaSupport | |
| theorem sum_cube_succ {n : β} (F : Cube (Fin (n + 1)) β β) : | |
| β x, F x = β b : Bool, β y : Cube (Fin n), F (Fin.cons b y) := by | |
| rw [β (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp] | |
| exact Fintype.sum_prod_type _ | |
| theorem expect_cube_succ {n : β} (F : Cube (Fin (n + 1)) β β) : | |
| (πΌ x, F x) = πΌ b : Bool, πΌ y : Cube (Fin n), F (Fin.cons b y) := by | |
| calc | |
| _ = πΌ p : Bool Γ Cube (Fin n), F (Fin.cons p.1 p.2) := | |
| (Fintype.expect_equiv (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)) _ F (fun _ => rfl)).symm | |
| _ = _ := by rw [β Finset.univ_product_univ, Finset.expect_product] | |
| theorem expect_bool (F : Bool β β) : (πΌ b, F b) = (F false + F true) / 2 := by | |
| rw [Fintype.expect_eq_sum_div_card] | |
| simp [add_comm] | |
| noncomputable def polynomial {I : Type*} [Fintype I] [DecidableEq I] | |
| (c : Cube I β β) (x : Cube I) : β := β s, c s * walsh s x | |
| noncomputable def energy {I : Type*} [Fintype I] [DecidableEq I] | |
| (c : Cube I β β) : β := | |
| β s, (β i, if s i then (3 : β) else 1) * c s ^ 2 | |
| theorem energy_nonneg {I : Type*} [Fintype I] [DecidableEq I] (c : Cube I β β) : | |
| 0 β€ energy c := by | |
| apply Finset.sum_nonneg | |
| intro s _ | |
| apply mul_nonneg _ (sq_nonneg _) | |
| apply Finset.prod_nonneg | |
| intro i _ | |
| split_ifs <;> norm_num | |
| theorem walsh_cons {n : β} (s x : Cube (Fin n)) (a b : Bool) : | |
| walsh (Fin.cons a s) (Fin.cons b x) = (if a then bitSign b else 1) * walsh s x := by | |
| cases a <;> simp [walsh, Fin.prod_univ_succ, bitSign] | |
| theorem polynomial_cons {n : β} (c : Cube (Fin (n + 1)) β β) (x : Cube (Fin n)) (b : Bool) : | |
| polynomial c (Fin.cons b x) = polynomial (fun s => c (Fin.cons false s)) x + | |
| bitSign b * polynomial (fun s => c (Fin.cons true s)) x := by | |
| unfold polynomial | |
| rw [sum_cube_succ, Fintype.sum_bool] | |
| simp only [walsh_cons, Bool.false_eq_true, βreduceIte, one_mul] | |
| rw [Finset.mul_sum, add_comm] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| ring | |
| theorem energy_cons {n : β} (c : Cube (Fin (n + 1)) β β) : | |
| energy c = energy (fun s => c (Fin.cons false s)) + | |
| 3 * energy (fun s => c (Fin.cons true s)) := by | |
| unfold energy | |
| rw [sum_cube_succ, Fintype.sum_bool] | |
| simp only [Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, Bool.false_eq_true, βreduceIte, | |
| one_mul, mul_assoc] | |
| rw [β Finset.mul_sum] | |
| ring | |
| theorem fourth_moment_cons {n : β} (c : Cube (Fin (n + 1)) β β) : | |
| (πΌ x, polynomial c x ^ 4) = | |
| (πΌ x, polynomial (fun s => c (Fin.cons false s)) x ^ 4) + | |
| 6 * (πΌ x, polynomial (fun s => c (Fin.cons false s)) x ^ 2 * | |
| polynomial (fun s => c (Fin.cons true s)) x ^ 2) + | |
| (πΌ x, polynomial (fun s => c (Fin.cons true s)) x ^ 4) := by | |
| rw [expect_cube_succ, Finset.expect_comm] | |
| simp_rw [expect_bool] | |
| simp only [polynomial_cons, bitSign, Bool.false_eq_true, βreduceIte, one_mul, neg_one_mul] | |
| simp_rw [show β a b : β, ((a + b) ^ 4 + (a + -b) ^ 4) / 2 = a ^ 4 + 6 * (a ^ 2 * b ^ 2) + b ^ 4 by | |
| intro a b; ring] | |
| rw [Finset.expect_add_distrib, Finset.expect_add_distrib, β Finset.mul_expect] | |
| theorem fourth_moment_bound (n : β) (c : Cube (Fin n) β β) : | |
| (πΌ x, polynomial c x ^ 4) β€ energy c ^ 2 := by | |
| induction n with | |
| | zero => simp [polynomial, energy, walsh]; exact le_of_eq (by ring) | |
| | succ n ih => | |
| let cβ : Cube (Fin n) β β := fun s => c (Fin.cons false s) | |
| let cβ : Cube (Fin n) β β := fun s => c (Fin.cons true s) | |
| have hβ := ih cβ | |
| have hβ := ih cβ | |
| have heβ := energy_nonneg cβ | |
| have heβ := energy_nonneg cβ | |
| have hmβ : 0 β€ πΌ x, polynomial cβ x ^ 4 := by positivity | |
| have hmβ : 0 β€ πΌ x, polynomial cβ x ^ 4 := by positivity | |
| have hc := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ | |
| (fun x => polynomial cβ x ^ 2) (fun x => polynomial cβ x ^ 2) | |
| simp only [β pow_mul, Nat.reduceMul] at hc | |
| have hc' : (πΌ x, polynomial cβ x ^ 2 * polynomial cβ x ^ 2) ^ 2 β€ | |
| (energy cβ * energy cβ) ^ 2 := by | |
| calc _ β€ _ := hc | |
| _ β€ energy cβ ^ 2 * energy cβ ^ 2 := mul_le_mul hβ hβ hmβ (sq_nonneg _) | |
| _ = _ := by ring | |
| have hc'' : (πΌ x, polynomial cβ x ^ 2 * polynomial cβ x ^ 2) β€ energy cβ * energy cβ := | |
| (sq_le_sqβ (by positivity) (mul_nonneg heβ heβ)).mp hc' | |
| rw [fourth_moment_cons, energy_cons] | |
| change (πΌ x, polynomial cβ x ^ 4) + | |
| 6 * (πΌ x, polynomial cβ x ^ 2 * polynomial cβ x ^ 2) + | |
| (πΌ x, polynomial cβ x ^ 4) β€ (energy cβ + 3 * energy cβ) ^ 2 | |
| nlinarith [sq_nonneg (energy cβ)] | |
| theorem weight_eq_degree {I : Type*} [Fintype I] [DecidableEq I] (s : Cube I) : | |
| (β i, if s i then (3 : β) else 1) = 3 ^ Analytic.degree s := by | |
| simp [Finset.prod_ite, Analytic.degree] | |
| theorem energy_truncated {I : Type*} [Fintype I] [DecidableEq I] | |
| (K : β) (c : Cube I β β) (hc : β s, K < Analytic.degree s β c s = 0) : | |
| energy c β€ 3 ^ K * β s, c s ^ 2 := by | |
| unfold energy | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_le_sum | |
| intro s _ | |
| rw [weight_eq_degree] | |
| by_cases hs : Analytic.degree s β€ K | |
| Β· exact mul_le_mul_of_nonneg_right (pow_le_pow_rightβ (by norm_num) hs) (sq_nonneg _) | |
| Β· rw [hc s (lt_of_not_ge hs)]; simp | |
| theorem coefficient_polynomial {I : Type*} [Fintype I] [DecidableEq I] | |
| (c : Cube I β β) (a : Cube I) : coefficient (polynomial c) a = c a := by | |
| unfold coefficient polynomial | |
| simp only [Finset.sum_mul] | |
| rw [Finset.expect_sum_comm] | |
| simp_rw [mul_assoc, β Finset.mul_expect, walsh_orthogonality] | |
| simp | |
| theorem polynomial_second_moment {I : Type*} [Fintype I] [DecidableEq I] (c : Cube I β β) : | |
| (πΌ x, polynomial c x ^ 2) = β s, c s ^ 2 := by | |
| rw [β walsh_parseval] | |
| simp only [coefficient_polynomial] | |
| theorem degree_fourth_moment_bound {n K : β} (c : Cube (Fin n) β β) | |
| (hc : β s, K < Analytic.degree s β c s = 0) : | |
| (πΌ x, polynomial c x ^ 4) β€ (3 ^ K * (πΌ x, polynomial c x ^ 2)) ^ 2 := by | |
| rw [polynomial_second_moment] | |
| exact (fourth_moment_bound n c).trans | |
| ((sq_le_sqβ (energy_nonneg c) (by positivity)).mpr (energy_truncated K c hc)) | |
| theorem degree_third_moment_bound {n K : β} (c : Cube (Fin n) β β) | |
| (hc : β s, K < Analytic.degree s β c s = 0) {Ο : β} (hΟ : 0 β€ Ο) | |
| (hsmall : (πΌ x, polynomial c x ^ 2) β€ Ο ^ 2) : | |
| (πΌ x, |polynomial c x| ^ 3) β€ 3 ^ K * Ο * (πΌ x, polynomial c x ^ 2) := by | |
| have hsecond : 0 β€ πΌ x, polynomial c x ^ 2 := by positivity | |
| have hfourth := degree_fourth_moment_bound c hc | |
| have hCS := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ | |
| (fun x => |polynomial c x|) (fun x => polynomial c x ^ 2) | |
| have hp (a : β) : |a| * a ^ 2 = |a| ^ 3 := by rw [β sq_abs]; ring | |
| simp_rw [hp, sq_abs, β pow_mul, Nat.reduceMul] at hCS | |
| have hbound : (πΌ x, |polynomial c x| ^ 3) ^ 2 β€ | |
| (3 ^ K * Ο * (πΌ x, polynomial c x ^ 2)) ^ 2 := by | |
| calc | |
| _ β€ (πΌ x, polynomial c x ^ 2) * (πΌ x, polynomial c x ^ 4) := hCS | |
| _ β€ (πΌ x, polynomial c x ^ 2) * (3 ^ K * (πΌ x, polynomial c x ^ 2)) ^ 2 := | |
| mul_le_mul_of_nonneg_left hfourth hsecond | |
| _ = (3 ^ K * (πΌ x, polynomial c x ^ 2)) ^ 2 * (πΌ x, polynomial c x ^ 2) := by ring | |
| _ β€ (3 ^ K * (πΌ x, polynomial c x ^ 2)) ^ 2 * Ο ^ 2 := | |
| mul_le_mul_of_nonneg_left hsmall (sq_nonneg _) | |
| _ = _ := by ring | |
| exact (sq_le_sqβ (by positivity) (by positivity)).mp hbound | |
| theorem walsh_flip {I : Type*} [Fintype I] [DecidableEq I] | |
| (s x : Cube I) (i : I) : | |
| walsh s (Function.update x i (!x i)) = (if s i then -1 else 1) * walsh s x := by | |
| classical | |
| have hp (j : I) : bitSign (s j && Function.update x i (!x i) j) = | |
| (if j = i then (if s i then (-1 : β) else 1) else 1) * bitSign (s j && x j) := by | |
| by_cases h : j = i | |
| Β· subst j; cases s i <;> cases x i <;> simp [bitSign] | |
| Β· simp [h] | |
| simp only [walsh, hp, Finset.prod_mul_distrib] | |
| simp | |
| noncomputable def discreteDiff {I : Type*} [Fintype I] [DecidableEq I] | |
| (f : Cube I β β) (i : I) (x : Cube I) : β := (f x - f (Function.update x i (!x i))) / 2 | |
| theorem polynomial_diff {I : Type*} [Fintype I] [DecidableEq I] | |
| (c : Cube I β β) (i : I) : | |
| discreteDiff (polynomial c) i = polynomial (fun s => if s i then c s else 0) := by | |
| funext x | |
| simp only [discreteDiff, polynomial, walsh_flip, β Finset.sum_sub_distrib, Finset.sum_div] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| cases s i <;> simp | |
| theorem total_diff_second {I : Type*} [Fintype I] [DecidableEq I] | |
| (c : Cube I β β) : | |
| (β i, πΌ x, discreteDiff (polynomial c) i x ^ 2) = | |
| β s, (Analytic.degree s : β) * c s ^ 2 := by | |
| simp only [polynomial_diff, polynomial_second_moment] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| simp only [ite_pow, zero_pow (by omega : 2 β 0)] | |
| rw [β Finset.sum_filter] | |
| simp [Analytic.degree] | |
| theorem total_diff_second_truncated {I : Type*} [Fintype I] [DecidableEq I] | |
| (K : β) (c : Cube I β β) (hc : β s, K < Analytic.degree s β c s = 0) : | |
| (β i, πΌ x, discreteDiff (polynomial c) i x ^ 2) β€ | |
| K * (πΌ x, polynomial c x ^ 2) := by | |
| rw [total_diff_second, polynomial_second_moment, Finset.mul_sum] | |
| apply Finset.sum_le_sum | |
| intro s _ | |
| by_cases hs : Analytic.degree s β€ K | |
| Β· exact mul_le_mul_of_nonneg_right (by exact_mod_cast hs) (sq_nonneg _) | |
| Β· rw [hc s (lt_of_not_ge hs)]; simp | |
| theorem total_diff_third_truncated {n K : β} (c : Cube (Fin n) β β) | |
| (hc : β s, K < Analytic.degree s β c s = 0) {Ο : β} (hΟ : 0 β€ Ο) | |
| (hsmall : β i, (πΌ x, discreteDiff (polynomial c) i x ^ 2) β€ Ο ^ 2) : | |
| (β i, πΌ x, |discreteDiff (polynomial c) i x| ^ 3) β€ | |
| 3 ^ K * Ο * K * (πΌ x, polynomial c x ^ 2) := by | |
| calc | |
| _ β€ β i, 3 ^ K * Ο * (πΌ x, discreteDiff (polynomial c) i x ^ 2) := by | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| have hi := hsmall i | |
| rw [polynomial_diff] at hi β’ | |
| exact degree_third_moment_bound _ (fun s hs => by rw [hc s hs]; split_ifs <;> rfl) | |
| hΟ hi | |
| _ = 3 ^ K * Ο * (β i, πΌ x, discreteDiff (polynomial c) i x ^ 2) := by rw [Finset.mul_sum] | |
| _ β€ 3 ^ K * Ο * (K * (πΌ x, polynomial c x ^ 2)) := | |
| mul_le_mul_of_nonneg_left (total_diff_second_truncated K c hc) (by positivity) | |
| _ = _ := by ring | |
| end DFVSMaxCut.BooleanFourthMoment | |
| namespace DirectedFeedback.Junta | |
| open scoped BigOperators | |
| open Finset DirectedFeedback.JuntaSupport DFVSMaxCut.BooleanFourthMoment | |
| open DFVSMaxCut.Analytic | |
| def influence {n : β} (f : Cube (Fin n) β β) (i : Fin n) : β := | |
| πΌ x, (f x - f (Function.update x i (!x i))) ^ 2 | |
| def totalInfluence {n : β} (f : Cube (Fin n) β β) : β := β i, influence f i | |
| def IsBoolean {n : β} (f : Cube (Fin n) β β) : Prop := β x, f x = 0 β¨ f x = 1 | |
| def OnCoordinates {n : β} (J : Finset (Fin n)) (f : Cube (Fin n) β β) : Prop := | |
| β x y, (β i β J, x i = y i) β f x = f y | |
| def error {n : β} (f g : Cube (Fin n) β β) : β := | |
| πΌ x, if f x = g x then 0 else 1 | |
| theorem polynomial_coefficients {n : β} (f : Cube (Fin n) β β) : | |
| polynomial (coefficient f) = f := by | |
| funext x | |
| exact walsh_inversion f x | |
| theorem influence_nonneg {n : β} (f : Cube (Fin n) β β) (i : Fin n) : | |
| 0 β€ influence f i := by unfold influence; positivity | |
| theorem influence_eq_diff {n : β} (f : Cube (Fin n) β β) (i : Fin n) : | |
| influence f i = 4 * (πΌ x, discreteDiff f i x ^ 2) := by | |
| rw [Finset.mul_expect] | |
| apply Finset.expect_congr rfl | |
| intro x _ | |
| unfold discreteDiff | |
| ring | |
| theorem totalInfluence_spectral {n : β} (f : Cube (Fin n) β β) : | |
| totalInfluence f = 4 * β s, (degree s : β) * coefficient f s ^ 2 := by | |
| unfold totalInfluence | |
| simp_rw [influence_eq_diff] | |
| rw [β Finset.mul_sum] | |
| conv_lhs => rw [β polynomial_coefficients f] | |
| rw [total_diff_second] | |
| theorem spectral_tail {n : β} (f : Cube (Fin n) β β) (K : β) : | |
| 4 * (K + 1 : β) * | |
| (β s β Finset.univ.filter (fun s => K < degree s), coefficient f s ^ 2) β€ | |
| totalInfluence f := by | |
| rw [totalInfluence_spectral, mul_assoc] | |
| apply mul_le_mul_of_nonneg_left _ (by norm_num : (0 : β) β€ 4) | |
| rw [Finset.mul_sum] | |
| calc | |
| _ β€ β s β Finset.univ.filter (fun s => K < degree s), | |
| (degree s : β) * coefficient f s ^ 2 := by | |
| apply Finset.sum_le_sum | |
| intro s hs | |
| apply mul_le_mul_of_nonneg_right _ (sq_nonneg _) | |
| exact_mod_cast Nat.succ_le_of_lt (Finset.mem_filter.mp hs).2 | |
| _ β€ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) | |
| (fun s _ _ => mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _)) | |
| def pivotal {n : β} (f : Cube (Fin n) β β) (i : Fin n) | |
| (x : Cube (Fin n)) : β := if f x = f (Function.update x i (!x i)) then 0 else 1 | |
| theorem pivotal_sq {n : β} (f : Cube (Fin n) β β) (i : Fin n) | |
| (x : Cube (Fin n)) : pivotal f i x ^ 2 = pivotal f i x := by | |
| unfold pivotal | |
| split_ifs <;> norm_num | |
| theorem diff_mul_pivotal {n : β} (f : Cube (Fin n) β β) (i : Fin n) | |
| (x : Cube (Fin n)) : discreteDiff f i x * pivotal f i x = discreteDiff f i x := by | |
| unfold pivotal discreteDiff | |
| split_ifs with h | |
| Β· simp [h] | |
| Β· ring | |
| theorem pivotal_eq_difference_sq {n : β} (f : Cube (Fin n) β β) (hf : IsBoolean f) | |
| (i : Fin n) (x : Cube (Fin n)) : | |
| pivotal f i x = (f x - f (Function.update x i (!x i))) ^ 2 := by | |
| unfold pivotal | |
| rcases hf x with h | h <;> | |
| rcases hf (Function.update x i (!x i)) with h' | h' <;> simp [h, h'] | |
| theorem expect_pivotal {n : β} (f : Cube (Fin n) β β) (hf : IsBoolean f) (i : Fin n) : | |
| (πΌ x, pivotal f i x) = influence f i := by | |
| unfold influence | |
| simp only [pivotal_eq_difference_sq f hf] | |
| def lowDiffCoeff {n : β} (f : Cube (Fin n) β β) (K : β) (i : Fin n) | |
| (s : Cube (Fin n)) : β := if s i = true β§ degree s β€ K then coefficient f s else 0 | |
| def lowDiff {n : β} (f : Cube (Fin n) β β) (K : β) (i : Fin n) := | |
| polynomial (lowDiffCoeff f K i) | |
| theorem coefficient_discreteDiff {n : β} (f : Cube (Fin n) β β) | |
| (i : Fin n) (s : Cube (Fin n)) : | |
| coefficient (discreteDiff f i) s = if s i then coefficient f s else 0 := by | |
| conv_lhs => rw [β polynomial_coefficients f] | |
| rw [polynomial_diff, coefficient_polynomial] | |
| theorem inner_lowDiff {n : β} (f : Cube (Fin n) β β) (K : β) (i : Fin n) : | |
| (πΌ x, discreteDiff f i x * lowDiff f K i x) = | |
| (πΌ x, lowDiff f K i x ^ 2) := by | |
| rw [β walsh_inner] | |
| simp only [lowDiff, coefficient_polynomial, coefficient_discreteDiff, | |
| polynomial_second_moment] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| unfold lowDiffCoeff | |
| by_cases hs : s i = true <;> by_cases hk : degree s β€ K <;> simp [hs, hk, pow_two] | |
| theorem lowDiff_fourth {n : β} (f : Cube (Fin n) β β) (K : β) (i : Fin n) : | |
| (πΌ x, lowDiff f K i x ^ 4) β€ | |
| (3 ^ K * (πΌ x, lowDiff f K i x ^ 2)) ^ 2 := by | |
| apply degree_fourth_moment_bound | |
| intro s hs | |
| simp [lowDiffCoeff, not_le.mpr hs] | |
| theorem lowDiff_energy_le {n : β} (f : Cube (Fin n) β β) (hf : IsBoolean f) | |
| (K : β) (i : Fin n) (Ο : β) (hΟ : 0 β€ Ο) (hsmall : influence f i β€ Ο ^ 2) : | |
| (πΌ x, lowDiff f K i x ^ 2) β€ 3 ^ K * Ο * influence f i / 4 := by | |
| let s := (πΌ x, lowDiff f K i x ^ 2) | |
| let X := (πΌ x, pivotal f i x * lowDiff f K i x ^ 2) | |
| let I := influence f i | |
| let a : β := 3 ^ K | |
| have hs0 : 0 β€ s := by dsimp [s]; positivity | |
| have hI0 : 0 β€ I := influence_nonneg f i | |
| have hX : 0 β€ X := by | |
| apply Finset.expect_nonneg | |
| intro x _ | |
| apply mul_nonneg _ (sq_nonneg _) | |
| unfold pivotal | |
| split_ifs <;> norm_num | |
| have ha0 : 0 β€ a := by dsimp [a]; positivity | |
| have hcβ := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ | |
| (discreteDiff f i) (fun x => pivotal f i x * lowDiff f K i x) | |
| have hinner : (πΌ x, discreteDiff f i x * | |
| (pivotal f i x * lowDiff f K i x)) = s := by | |
| simp only [β mul_assoc, diff_mul_pivotal, inner_lowDiff] | |
| rfl | |
| have hprod : (πΌ x, (pivotal f i x * lowDiff f K i x) ^ 2) = X := by | |
| simp only [mul_pow, pivotal_sq] | |
| rfl | |
| rw [hinner, hprod] at hcβ | |
| have hIdiff : (πΌ x, discreteDiff f i x ^ 2) = I / 4 := by | |
| have hh := influence_eq_diff f i | |
| dsimp [I] | |
| linarith | |
| rw [hIdiff] at hcβ | |
| have hcβ := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ | |
| (pivotal f i) (fun x => lowDiff f K i x ^ 2) | |
| simp only [pivotal_sq, expect_pivotal f hf, β pow_mul, Nat.reduceMul] at hcβ | |
| have hcβ' : X ^ 2 β€ I * (a * s) ^ 2 := by | |
| exact hcβ.trans (mul_le_mul_of_nonneg_left (lowDiff_fourth f K i) hI0) | |
| by_cases hs : s = 0 | |
| Β· change s β€ a * Ο * I / 4 | |
| rw [hs] | |
| positivity | |
| have hspos : 0 < s := lt_of_le_of_ne hs0 (Ne.symm hs) | |
| have hsq : s ^ 4 β€ (I / 4) ^ 2 * (I * (a * s) ^ 2) := by | |
| calc | |
| s ^ 4 = (s ^ 2) ^ 2 := by ring | |
| _ β€ (I / 4 * X) ^ 2 := | |
| (sq_le_sqβ (sq_nonneg _) (by positivity)).mpr hcβ | |
| _ = (I / 4) ^ 2 * X ^ 2 := by ring | |
| _ β€ _ := mul_le_mul_of_nonneg_left hcβ' (sq_nonneg _) | |
| have hcancel : s ^ 2 β€ a ^ 2 * I ^ 3 / 16 := by | |
| apply (mul_le_mul_iff_of_pos_left (sq_pos_of_pos hspos)).mp | |
| nlinarith only [hsq] | |
| have hsmall' : a ^ 2 * I ^ 3 / 16 β€ (a * Ο * I / 4) ^ 2 := by | |
| have hh := mul_le_mul_of_nonneg_left hsmall (by positivity : 0 β€ a ^ 2 * I ^ 2 / 16) | |
| dsimp [I] at * | |
| nlinarith only [hh] | |
| exact (sq_le_sqβ hs0 (by positivity)).mp (hcancel.trans hsmall') | |
| def support {n : β} (s : Cube (Fin n)) : Finset (Fin n) := | |
| Finset.univ.filter (fun i => s i = true) | |
| def projectCoeff {n : β} (J : Finset (Fin n)) (f : Cube (Fin n) β β) | |
| (s : Cube (Fin n)) : β := if support s β J then coefficient f s else 0 | |
| def project {n : β} (J : Finset (Fin n)) (f : Cube (Fin n) β β) := | |
| polynomial (projectCoeff J f) | |
| theorem walsh_eq_on_support {n : β} (s x y : Cube (Fin n)) | |
| (hxy : β i β support s, x i = y i) : walsh s x = walsh s y := by | |
| apply Finset.prod_congr rfl | |
| intro i _ | |
| by_cases hi : s i = true | |
| Β· rw [hxy i (by simp [support, hi])] | |
| Β· simp [Bool.eq_false_of_not_eq_true hi] | |
| theorem project_onCoordinates {n : β} (J : Finset (Fin n)) (f : Cube (Fin n) β β) : | |
| OnCoordinates J (project J f) := by | |
| intro x y hxy | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| by_cases hs : support s β J | |
| Β· rw [walsh_eq_on_support s x y (fun i hi => hxy i (hs hi))] | |
| Β· simp [projectCoeff, hs] | |
| theorem coefficient_sub {n : β} (f g : Cube (Fin n) β β) (s : Cube (Fin n)) : | |
| coefficient (fun x => f x - g x) s = coefficient f s - coefficient g s := by | |
| unfold coefficient | |
| simp only [sub_mul, Finset.expect_sub_distrib] | |
| theorem project_squared_error {n : β} (J : Finset (Fin n)) (f : Cube (Fin n) β β) : | |
| (πΌ x, (f x - project J f x) ^ 2) = | |
| β s, if support s β J then 0 else coefficient f s ^ 2 := by | |
| rw [β walsh_parseval] | |
| simp only [coefficient_sub, project, coefficient_polynomial] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| unfold projectCoeff | |
| split_ifs <;> simp | |
| theorem project_squared_error_le {n : β} (J : Finset (Fin n)) | |
| (f : Cube (Fin n) β β) (K : β) : | |
| (πΌ x, (f x - project J f x) ^ 2) β€ | |
| (β s β Finset.univ.filter (fun s => K < degree s), coefficient f s ^ 2) + | |
| β i β Finset.univ \ J, (πΌ x, lowDiff f K i x ^ 2) := by | |
| rw [project_squared_error] | |
| simp only [lowDiff, polynomial_second_moment] | |
| rw [Finset.sum_filter, Finset.sum_comm, β Finset.sum_add_distrib] | |
| apply Finset.sum_le_sum | |
| intro s _ | |
| by_cases hs : support s β J | |
| Β· rw [ite_eq_left hs] | |
| positivity | |
| Β· rw [ite_eq_right hs] | |
| by_cases hk : K < degree s | |
| Β· rw [ite_eq_left hk] | |
| exact le_add_of_nonneg_right (Finset.sum_nonneg (fun i _ => sq_nonneg _)) | |
| Β· rw [ite_eq_right hk, zero_add] | |
| obtain β¨i, hi, hiJβ© := Finset.not_subset.mp hs | |
| have his : s i = true := (Finset.mem_filter.mp hi).2 | |
| have hiout : i β Finset.univ \ J := by simp [hiJ] | |
| have hterm : lowDiffCoeff f K i s = coefficient f s := by | |
| simp [lowDiffCoeff, his, Nat.le_of_not_gt hk] | |
| rw [β hterm] | |
| exact Finset.single_le_sum (fun i _ => sq_nonneg (lowDiffCoeff f K i s)) hiout | |
| def highInfluences {n : β} (f : Cube (Fin n) β β) (Ο : β) : Finset (Fin n) := | |
| Finset.univ.filter (fun i => Ο ^ 2 < influence f i) | |
| theorem highInfluences_card_bound {n : β} (f : Cube (Fin n) β β) (Ο : β) : | |
| (highInfluences f Ο).card * Ο ^ 2 β€ totalInfluence f := by | |
| calc | |
| _ = β i β highInfluences f Ο, Ο ^ 2 := by simp | |
| _ β€ β i β highInfluences f Ο, influence f i := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| exact (Finset.mem_filter.mp hi).2.le | |
| _ β€ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) fun i _ _ => | |
| influence_nonneg f i | |
| theorem lowDiff_sum_outside {n : β} (f : Cube (Fin n) β β) (hf : IsBoolean f) | |
| (K : β) (Ο : β) (hΟ : 0 β€ Ο) : | |
| (β i β Finset.univ \ highInfluences f Ο, (πΌ x, lowDiff f K i x ^ 2)) β€ | |
| 3 ^ K * Ο * totalInfluence f / 4 := by | |
| calc | |
| _ β€ β i β Finset.univ \ highInfluences f Ο, 3 ^ K * Ο * influence f i / 4 := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| apply lowDiff_energy_le f hf K i Ο hΟ | |
| have hnot := (Finset.mem_sdiff.mp hi).2 | |
| simpa only [highInfluences, Finset.mem_filter, Finset.mem_univ, true_and, not_lt] using hnot | |
| _ β€ β i, 3 ^ K * Ο * influence f i / 4 := | |
| Finset.sum_le_sum_of_subset_of_nonneg (Finset.sdiff_subset.trans (Finset.subset_univ _)) | |
| (fun i _ _ => by have := influence_nonneg f i; positivity) | |
| _ = _ := by rw [β Finset.sum_div, β Finset.mul_sum]; rfl | |
| end DirectedFeedback.Junta | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end OAI | |